package com.gzw.dms.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gzw.dms.R;
import com.gzw.dms.bean.AbnormalReportInfo;
import com.gzw.dms.bean.BackOrderInfo;
import com.gzw.dms.bean.ShippingOrderInfo;

import java.util.List;

/**
 * Created by Administrator on 2016/9/12.
 */
public class BackAdatper extends RecyclerView.Adapter{
    public static interface OnRecyclerViewListener {
        void onItemClick(int position);
        boolean onItemLongClick(int position);
    }
    private OnRecyclerViewListener onRecyclerViewListener;
    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }
    private static final String TAG = BackAdatper.class.getSimpleName();
    private List<BackOrderInfo> list;
    public BackAdatper(List<BackOrderInfo> list) {
        this.list = list;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_backorderadatper, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        PersonViewHolder holder = (PersonViewHolder) viewHolder;
        holder.position = i;
        BackOrderInfo shippingOrderInfo = list.get(i);
        holder.tv_shiping_order_num.setText("货运编号:"+shippingOrderInfo.getShiping_order_num());
        holder.tv_order_goid.setText("调拨/退货始发位置:"+shippingOrderInfo.getEnd_address());

        holder.tv_send_time.setText("通知时间:"+shippingOrderInfo.getUpdatetime());
        holder.tv_custom_name.setText("发货客户名称:"+shippingOrderInfo.getCustom_name());
        holder.tv_receipt_name.setText("发货客户电话:"+shippingOrderInfo.getCustom_tel());
        holder.tv_sx.setText("提货时效:" + shippingOrderInfo.getTime_limitation());
        holder.tv_sign_time.setText("总件数:" + shippingOrderInfo.getGoods_num());
        holder.tv_edit.setText("备注:"+shippingOrderInfo.getRemarks_order());


    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        public View rootView;
        public TextView tv_order_goid;
        public TextView tv_shiping_order_num;
        public TextView tv_send_time;
        public TextView tv_end_address;
        public TextView tv_custom_name;
        public TextView tv_receipt_name;
        public TextView tv_sx;
        public TextView tv_sign_time;
        public TextView tv_edit;
        public int position;
        public PersonViewHolder(View itemView) {
            super(itemView);
            tv_order_goid = (TextView) itemView.findViewById(R.id.ic_shiping_order_goid).findViewById(R.id.tv_name);
            tv_shiping_order_num = (TextView) itemView.findViewById(R.id.ic_shiping_order_num).findViewById(R.id.tv_name);
            tv_send_time = (TextView) itemView.findViewById(R.id.ic_send_time).findViewById(R.id.tv_name);
            tv_custom_name = (TextView) itemView.findViewById(R.id.ic_custom_name).findViewById(R.id.tv_name);
            tv_receipt_name = (TextView) itemView.findViewById(R.id.ic_receipt_name).findViewById(R.id.tv_name);
            tv_sx = (TextView) itemView.findViewById(R.id.ic_sx).findViewById(R.id.tv_name);
            tv_sign_time = (TextView) itemView.findViewById(R.id.ic_sign_time).findViewById(R.id.tv_name);
            tv_edit = (TextView) itemView.findViewById(R.id.tv_edit).findViewById(R.id.tv_name);
            rootView = itemView.findViewById(R.id.ll);
            rootView.setOnClickListener(this);
            rootView.setOnLongClickListener(this);
        }
        @Override
        public void onClick(View v) {
            if (null != onRecyclerViewListener) {
                onRecyclerViewListener.onItemClick(position);
            }
        }
        @Override
        public boolean onLongClick(View v) {
            if (null != onRecyclerViewListener) {
                return onRecyclerViewListener.onItemLongClick(position);
            }
            return false;
        }
    }
}
